home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / Miro_Installer.exe / xulrunner / python / license.py < prev    next >
Encoding:
Python Source  |  2008-01-10  |  2.0 KB  |  57 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. """Support for licensing in Miro-consumed feeds."""
  19.  
  20. from gtcache import gettext as _
  21. import rdfa
  22.  
  23. DC_TITLE = "http://purl.org/dc/elements/1.1/title"
  24.  
  25. class DictSink(object):
  26.     """Simple sink for the RDFa parser; stores triples in a nested dict
  27.     structure.  After parsing self[subject][predicate] contains a list 
  28.     of objects."""
  29.  
  30.     def __init__(self):
  31.  
  32.         self.data = {}
  33.  
  34.     def triple(self, s, p, o):
  35.         self.data.setdefault(s, {}).setdefault(p, []).append(o)
  36.  
  37. def license_name(license_uri):
  38.     """Attempt to determine the license name from the URI; if the name cannot
  39.     be determined, the URI is returned unchanged."""
  40.  
  41.     # retrieve the license document and parse it for RDFa
  42.     try:
  43.         sink = rdfa.parseURI(license_uri, sink=DictSink())
  44.  
  45.         # look for explicit assertions about the license URI first, 
  46.         # then fall back to looking for assertions about the document
  47.         license_name = sink.data.get(license_uri,
  48.                              sink.data[u''])[DC_TITLE][0].strip()
  49.  
  50.         # note this is parser-specific; swapping out rdfa.py
  51.         # may invalidate this extraction 
  52.         return license_name[1:license_name.find('"',1)]
  53.  
  54.     except (IOError, KeyError), e:
  55.         
  56.         return _('license page')
  57.